﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;

public class LuaGlobalEnv : MonoBehaviour
{
    private static LuaGlobalEnv instance;
    public LuaEnv luaEnv = new LuaEnv();


    public static LuaGlobalEnv Instance
    {
        get
        {
            if (instance == null)
                Instance = new LuaGlobalEnv();
            return instance;
        }

        private set
        {
            instance = value;
        }
    }

    private void Awake()
    {
        instance = this;
        Debug.Log(string.Format("<color=yellow>单例：{0} luaEnv：{1}</color>",instance.name,luaEnv.ToString()));
        //DontDestroyOnLoad(this.gameObject);
    }

    public byte[] MyLuaLoader(string filePath)
    {
        string absPath = Application.streamingAssetsPath + "/" + filePath + ".lua";
        return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(absPath));
    }


    private void OnDestroy()
    {
        luaEnv.Dispose();
        Instance = null;
    }
}
